package com.ydd.controller.admin;


import com.ydd.dto.RoleDTO;
import com.ydd.dto.RolePageDTO;
import com.ydd.dto.UserPageDTO;
import com.ydd.entity.Rewinfo;
import com.ydd.entity.Role;
import com.ydd.result.Result;
import com.ydd.service.IRoleService;
import com.ydd.vo.PageVO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author hgz
 * @since 2023-05-30
 */
@Slf4j
@RestController
@RequestMapping("/admin/sys_role")
public class RoleController {

    @Autowired
    private IRoleService roleService;

    @GetMapping("/list")
    @ApiOperation("角色分页列表")
    public Result<PageVO> pagelist(RolePageDTO rolePageDTO){
        log.info("用户分页列表：{}",rolePageDTO);
        PageVO pageR = roleService.page(rolePageDTO);
        return Result.success(pageR);
    }
    @PostMapping("/add")
    @ApiOperation("角色添加")
    public Result add(@RequestBody RoleDTO roleDTO){
        roleService.add(roleDTO);
        return Result.success();
    }
    @GetMapping("/del")
    @ApiOperation("角色删除")
    public Result delete( String id){

        roleService.delete(id);

        return Result.success();
    }
    @GetMapping("/rowInfo")
    @ApiOperation("根据角色id回显")
    public Result<Rewinfo> seleteById(String id){

        Rewinfo rewinfo=roleService.seleteByIdd(id);
        return Result.success(rewinfo);
    }
//    @PostMapping("/update")//没用body
//    @ApiOperation("根据角色id修改")
//    public Result update(@RequestBody RoleDTO role){
//        roleService.updatebyRole(role);
//        return Result.success();
//    }

    @GetMapping("/allDate")
    @ApiOperation("全部角色列表")
    public Result allDate()
    {
        return roleService.allDate();
    }

}
